/**
 ******************************************************************************
 * @file    main.c
 * @author  MCU Application Team
 * @brief   Main program body
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; Copyright (c) Puya Semiconductor Co.
 * All rights reserved.</center></h2>
 *
 * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under BSD 3-Clause license,
 * the "License"; You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                        opensource.org/licenses/BSD-3-Clause
 *
 ******************************************************************************
 */

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "bsp_usart.h"

#include "bsp_spi.h"
#include "lcd.h"
#include "pic.h"
#include "timer.h"
#include "bsp_gpio.h"


#define RED           	 0xF800

static void APP_SystemClockConfig(void);

// BSP 级 函数初始化函数声明
static void APP_Init(void)
{

	USART2_Config();

//	timer_init();	 /* 初始化定时器 */

	bsp_spi2_init(); // 初始化SPI2
	bsp_gpio_init();

	LCD_Init(); // 初始化LCD
//	LCD_ShowPicture_DMA(0,0,LCD_W,LCD_H,te);
	LCD_Fill(0,0,LCD_W,LCD_H,RED);



}
/**
 * @brief  应用程序入口函数.
 * @retval int
 */
int main(void)
	
{
	/* 初始化所有外设，Flash接口，SysTick */
	HAL_Init();

	/* 系统时钟配置 */
	APP_SystemClockConfig();
	APP_Init();
	
	
	while (1)
	{
		

	}
}

static void APP_SystemClockConfig(void)
{
	RCC_OscInitTypeDef OscInitstruct = {0};
	RCC_ClkInitTypeDef ClkInitstruct = {0};

	OscInitstruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE |
								   RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSI48M;
	OscInitstruct.HSEState = RCC_HSE_ON;					 /* 开启HSE */
	OscInitstruct.HSEFreq = RCC_HSE_16_32MHz;				 /* 选择HSE频率4-8M */
	OscInitstruct.HSI48MState = RCC_HSI48M_OFF;				 /* 关闭HSI48M */
	OscInitstruct.HSIState = RCC_HSI_ON;					 /* 开启HSI */
	OscInitstruct.LSEState = RCC_LSE_OFF;					 /* 关闭LSE */
	/* OscInitstruct.LSEDriver       = RCC_LSEDRIVE_HIGH; */ /* 驱动能力等级：高 */
	OscInitstruct.LSIState = RCC_LSI_OFF;					 /* 关闭LSI */
	OscInitstruct.PLL.PLLState = RCC_PLL_ON;				 /* 开启PLL */
	OscInitstruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;		 /* PLL时钟源选择HSE */
	OscInitstruct.PLL.PLLMUL = RCC_PLL_MUL6;				 /* PLL时钟源6倍频 */
	/* 配置振荡器 */
	if (HAL_RCC_OscConfig(&OscInitstruct) != HAL_OK)
	{
		APP_ErrorHandler();
	}

	ClkInitstruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
	ClkInitstruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; /* 系统时钟选择PLL */
	ClkInitstruct.AHBCLKDivider = RCC_SYSCLK_DIV1;		  /* AHB时钟1分频 */
	ClkInitstruct.APB1CLKDivider = RCC_HCLK_DIV1;		  /* APB1时钟1分频 */
	ClkInitstruct.APB2CLKDivider = RCC_HCLK_DIV2;		  /* APB2时钟2分频 */
	/* 配置时钟 */
	if (HAL_RCC_ClockConfig(&ClkInitstruct, FLASH_LATENCY_5) != HAL_OK)
	{
		APP_ErrorHandler();
	}
	SystemCoreClockUpdate();
}

/**
 * @brief  错误执行函数
 * @param  无
 * @retval 无
 */
void APP_ErrorHandler(void)
{
	/* 无限循环 */
	while (1)
	{
		printf("Error occurred!\r\n");
		HAL_Delay(1000); // 延时1秒
	}
}

#ifdef USE_FULL_ASSERT
/**
 * @brief  输出产生断言错误的源文件名及行号
 * @param  file：源文件名指针
 * @param  line：发生断言错误的行号
 * @retval 无
 */
void assert_failed(uint8_t *file, uint32_t line)
{
	/* 用户可以根据需要添加自己的打印信息,
	   例如: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
	/* 无限循环 */
	while (1)
	{
	}
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
